package cn.stylefeng.guns.sys.modular.dataQualityCheck.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.dataQualityCheck.entity.QualityCheck;
import cn.stylefeng.guns.sys.modular.dataQualityCheck.model.params.QualityCheckParam;
import cn.stylefeng.guns.sys.modular.dataQualityCheck.service.QualityCheckService;
import cn.stylefeng.guns.sys.modular.metadata.model.params.MetadataParam;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 数据质量检查控制器
 *
 * @author author
 * @Date 2020-11-18 14:19:05
 */
@Controller
@RequestMapping("/qualityCheck")
public class QualityCheckController extends BaseController {

    private String PREFIX = "/modular/dataQualityCheck/qualityCheck";

    @Autowired
    private QualityCheckService qualityCheckService;

    /**
     * 跳转到主页面
     *
     * @author author
     * @Date 2020-11-18
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/qualityCheck.html";
    }

    /**
     * 新增页面
     *
     * @author author
     * @Date 2020-11-18
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/qualityCheck_add.html";
    }

    /**
     * 编辑页面
     *
     * @author author
     * @Date 2020-11-18
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/qualityCheck_edit.html";
    }

    /**
     * 新增接口
     *
     * @author author
     * @Date 2020-11-18
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(QualityCheckParam qualityCheckParam) {
        this.qualityCheckService.add(qualityCheckParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author author
     * @Date 2020-11-18
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(QualityCheckParam qualityCheckParam) {
        this.qualityCheckService.update(qualityCheckParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author author
     * @Date 2020-11-18
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(QualityCheckParam qualityCheckParam) {
        this.qualityCheckService.delete(qualityCheckParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author author
     * @Date 2020-11-18
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(QualityCheckParam qualityCheckParam) {
        QualityCheck detail = this.qualityCheckService.getById(qualityCheckParam.getDataQualityCheckId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author author
     * @Date 2020-11-18
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(QualityCheckParam qualityCheckParam) {
        return this.qualityCheckService.findPageBySpec(qualityCheckParam);
    }

    /**
     * 质量检查
     *
     * @author zhaoyiheng
     * @Date 2020-08-20
     */
    @ResponseBody
    @RequestMapping("/qualityCheck")
    public int qualityCheck(MetadataParam metadataParam) {
        return this.qualityCheckService.qualityCheckByMetadata(metadataParam);
    }

    /**
     * 批量退回
     *
     * @author zhaoyiheng
     * @Date 2020-08-20
     */
    @ResponseBody
    @RequestMapping("/allReturn")
    public int allReturn(@RequestParam int[] arr) {
        int number = 0;
        for (int i = 0; i < arr.length; i++) {
            this.qualityCheckService.returnQualityCheck(arr[i]);
            number++;
        }
        return number;
    }

    /**
     * 批量退回
     *
     * @author zhaoyiheng
     * @Date 2020-08-20
     */
    @ResponseBody
    @RequestMapping("/queryDepartment")
    public String queryDepartment(String metadataName) {
        List<String> list = this.qualityCheckService.queryDepartmentInfo(metadataName);
        return list.get(0);
    }

}


